import delimited "C:\Users\jp18390\Dropbox\DISCRIMINATION PROJECT (U.S. FEDERAL AGENCIES)\FEVS\FEVS_2010-2019\FEVS2012_PRDF.csv"
svyset [pweight=postwt]
drop if q17=="X"
drop if q17==""
drop if q37=="X"
drop if q37==""
drop if q38=="X"
drop if q38==""
drop if q15=="X"
drop if q15==""
drop if q22=="X"
drop if q22==""
drop if q25=="X"
drop if q25==""
drop if q33=="X"
drop if q33==""
drop if q48==.
drop if q49==.
destring q17, replace
destring q37, replace
destring q38, replace
destring q15, replace
destring q22, replace
destring q25, replace
destring q33, replace

svy linearized : sem (JUSTICE -> DISTRIBUTIVE, ) (JUSTICE -> PROCEDURAL, ) (JUSTICE -> INTERPERSONAL, ) (DISTRIBUTIVE -> q22, ) (DISTRIBUTIVE -> q25, ) (DISTRIBUTIVE -> q33, ) (PROCEDURAL -> q15, ) (PROCEDURAL -> q17, ) (PROCEDURAL -> q37, ) (PROCEDURAL -> q38, ) (INTERPERSONAL -> q48, ) (INTERPERSONAL -> q49, ), standardized latent(JUSTICE DISTRIBUTIVE PROCEDURAL INTERPERSONAL ) nocapslatent
estat gof, stats(all)
predict justice, latent(JUSTICE)
egen average_justice = mean (justice), by (agency)
egen sub_average_justice = mean (justice), by (subelem)
save "C:\Users\jp18390\Dropbox\DISCRIMINATION PROJECT (U.S. FEDERAL AGENCIES)\Age Discrimination Project\Organizational Justice_Factor Scores 2010-2019\2012FEVS_Justice.dta"

